package com.mauroleon.promotail.component;

import java.util.List;

import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.mauroleon.promotail.domain.Local;
import com.mauroleon.promotail.service.LocalService;

@Component
@Path("/locals")
public class LocalResourceComponent {

	@Autowired
	private LocalService localService;

	@GET
	@Produces(MediaType.APPLICATION_JSON)
	public List<Local> obtenerLocales() {
		return localService.findAll();
	}

	@GET
	@Path("/{idLocal}")
	@Produces(MediaType.APPLICATION_JSON)
	public Local obtenerLocal(@PathParam("idLocal") int idLocal) {
		return localService.findOne(idLocal);
	}

	@POST
	public void guardarLocal(Local local) {
		localService.save(local);
	}

	@DELETE
	public void eliminarLocal(Integer idLocal) {
		localService.delete(idLocal);
	}
}
